<template>
  <el-dialog
    title="关联角色"
    :visible.sync="showDialog"
    width="45%"
  >
    <el-checkbox-group v-model="checkRole">

      <el-checkbox v-for="item in allRoleList" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <div slot="footer">
      <el-button size="small" @click="showDialog = false">取 消</el-button>
      <el-button size="small" type="primary" @click="btnOK">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getEnableRoleApi } from '@/api/role'
import { assignRoleApi } from '@/api/imployee'
export default {
  data() {
    return {
      showDialog: false,
      allRoleList: [], // 所有角色
      checkRole: [], // 选中角色
      userId: ''
    }
  },
  created() {
    this.getAllRole()
  },
  methods: {
    // 获取所有角色
    async getAllRole() {
      const res = await getEnableRoleApi()
      console.log(res)
      this.allRoleList = res
    },
    // 员工关联角色提交
    async btnOK() {
      await assignRoleApi({
        id: this.userId,
        roleIds: this.checkRole
      })
      this.$message.success('操作成功')
      this.showDialog = false
    }
  }

}
</script>

<style>

</style>
